import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import axios from "axios";
import promise from "./common/ajax";
import Es6Promise       from 'es6-promise';
import ElementUI        from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import  api             from  './api/index';
import  nav             from  './config/NavConfig';
import  mapapi          from  './config/MapApiConfig';
import  components      from  './componentsChild/index';
import  echarts         from  'echarts';
import  common          from  './common/common';
import  raxios          from  './api/raxios';         //  封装的 axios 方法
new common(Vue);                                     //   实例化公共方法  全局挂载
import  route_          from  './common/route';
// import  socket          from  './api/socket';       //websocket 长连接

import moment from 'moment';                              //   时间操作模块
import config_    from './config/config';                 //   配置文件


new route_(Vue);                                      //   路由全局处理

Vue.use(ElementUI);
Vue.prototype.$mapapi = mapapi;
Vue.prototype.$raxios = raxios()
Vue.prototype.$promise = promise;
Vue.prototype.$echarts = echarts;
Vue.prototype.$moment = moment;

// Vue.prototype.$nav=nav;
// Vue.prototype.$nav = store.state.navMap;      //根据用户登陆后，获取到的左侧导航栏展示
Vue.prototype.$api=api;
Vue.prototype.$message=ElementUI.Message;
Vue.prototype.$config  = config_;
Es6Promise.polyfill();
Vue.config.productionTip = false;
components(Vue);

// Vue.prototype.$socket = socket;         //websocket 长连接


//刚开始第一次进入页面的时候，为了防止拿不到之前保留的token，先取拿一次内存
 localStorage.getItem("store") && store.replaceState(Object.assign(store.state,JSON.parse(localStorage.getItem("store"))));

new Vue({
  router,
  store,
  created(){
     //在页面刷新时将vuex里的信息保存到localStorage里
      window.addEventListener("beforeunload",()=>{
       localStorage.setItem("store",JSON.stringify(this.$store.state))
      })   
    //在页面加载时读取localStorage里的状态信息
      localStorage.getItem("store") && this.$store.replaceState(Object.assign(this.$store.state,JSON.parse(localStorage.getItem("store"))));
  },
  render: h => h(App)
}).$mount("#app");
